using Game.Core;
using Game.Main.Model;
using Game.Manager;
using Game.XH;
using SimpleJSON;
using UnityEngine;

namespace Game.Component
{
	public class FaceLiftLightItem : BaseItem
	{
		public enum State
		{
			Point1 = 0,
			Point2 = 1,
			Point3 = 2,
			Point4 = 3
		}

		public enum Anim
		{
			Static = 0,
			Roll = 1
		}

		private float angle1;

		private float angle2 = 20f;

		private float angle3 = 40f;

		private State state;

		private Anim anim;

		private float curAngleVal;

		private float targetAngleVal;

		private float animTimer;

		private Transform joint;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			joint = model.Find("Joint");
			joint.SetLocalZ(1E-05f);
			SetState((State)data.state);
		}

		protected override void LateUpdate()
		{
			if (anim == Anim.Roll)
			{
				animTimer += Time.deltaTime;
				joint.localEulerAngles = new Vector3(0f, 0f, Mathf.Lerp(curAngleVal, targetAngleVal, animTimer));
				if (animTimer >= 1f)
				{
					anim = Anim.Static;
				}
			}
		}

		public override void QuicklyTouch(TouchEventData touchEventData)
		{
			if (anim == Anim.Static)
			{
				base.QuicklyTouch(touchEventData);
				if (state == State.Point1)
				{
					curAngleVal = angle1;
					targetAngleVal = angle2;
					state = State.Point2;
				}
				else if (state == State.Point2)
				{
					curAngleVal = angle2;
					targetAngleVal = angle3;
					state = State.Point3;
				}
				else if (state == State.Point3)
				{
					curAngleVal = angle3;
					targetAngleVal = angle2;
					state = State.Point4;
				}
				else if (state == State.Point4)
				{
					curAngleVal = angle2;
					targetAngleVal = angle1;
					state = State.Point1;
				}
				animTimer = 0f;
				anim = Anim.Roll;
				Singleton<AudioManager>.Instance.PlaySound("sound_face_lift_light");
			}
		}

		private void SetState(State val)
		{
			if (state != val)
			{
				state = val;
				if (state == State.Point1)
				{
					joint.localEulerAngles = new Vector3(0f, 0f, angle2);
				}
				else if (state == State.Point2 || state == State.Point4)
				{
					joint.localEulerAngles = new Vector3(0f, 0f, angle3);
				}
				else if (state == State.Point3)
				{
					joint.localEulerAngles = new Vector3(0f, 0f, angle1);
				}
			}
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["33"] = (int)state;
		}
	}
}
